package com.ruoyi.his.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.his.domain.TMedicalDrugsStorage;
import com.ruoyi.his.domain.vo.TMedicalDrugsStorageVo;
import com.ruoyi.his.service.ITMedicalDrugsStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 药库Controller
 * 
 * @author ruoyi
 * @date 2021-09-10
 */
@RestController
@RequestMapping("/system/storage")
public class TMedicalDrugsStorageController extends BaseController
{
    @Autowired
    private ITMedicalDrugsStorageService tMedicalDrugsStorageService;

    /**
     * 查询药库列表
     */
    @PreAuthorize("@ss.hasPermi('system:storage:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMedicalDrugsStorageVo tMedicalDrugsStorage)
    {
        startPage();
        List<TMedicalDrugsStorageVo> list = tMedicalDrugsStorageService.selectTMedicalDrugsStorageList(tMedicalDrugsStorage);
        return getDataTable(list);
    }


    /**
     * 导出药库列表
     */
    @PreAuthorize("@ss.hasPermi('system:storage:export')")
    @Log(title = "药库", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TMedicalDrugsStorageVo tMedicalDrugsStorage)
    {
        List<TMedicalDrugsStorageVo> list = tMedicalDrugsStorageService.selectTMedicalDrugsStorageList(tMedicalDrugsStorage);
        ExcelUtil<TMedicalDrugsStorageVo> util = new ExcelUtil<TMedicalDrugsStorageVo>(TMedicalDrugsStorageVo.class);
        return util.exportExcel(list, "药库数据");
    }

    /**
     * 获取药库详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:storage:query')")
    @GetMapping(value = "/{storageid}")
    public AjaxResult getInfo(@PathVariable("storageid") Long storageid)
    {
        return AjaxResult.success(tMedicalDrugsStorageService.selectTMedicalDrugsStorageByStorageid(storageid));
    }

    /**
     * 新增药库
     */
    @PreAuthorize("@ss.hasPermi('system:storage:add')")
    @Log(title = "药库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMedicalDrugsStorage tMedicalDrugsStorage)
    {
        return toAjax(tMedicalDrugsStorageService.insertTMedicalDrugsStorage(tMedicalDrugsStorage));
    }

    /**
     * 修改药库
     */
    @PreAuthorize("@ss.hasPermi('system:storage:edit')")
    @Log(title = "药库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMedicalDrugsStorage tMedicalDrugsStorage)
    {
        return toAjax(tMedicalDrugsStorageService.updateTMedicalDrugsStorage(tMedicalDrugsStorage));
    }


}
